Package edu.uky.ai.tic.state
Class State
java.lang.Object
edu.uky.ai.tic.state.State
public class State
extends java.lang.Object
Represents the current state of a Tic Tac Toe game.
- Author:
- Stephen G. Ware
-
Constructor Summary
Constructors Constructor Description State()Constructs the initial state of all Tic Tac Toe games, in which the grid is empty and it is X's turn to move. -
Method Summary
Modifier and Type Method Description java.lang.Iterable<Move>getAvailableMoves()Returns a set of all the next moves that can be made in the game.PlayergetCurrentPlayer()Returns the player whose turn it is to move next.PlayergetSquare(int row, int column)Returns the mark at the given row and column of the grid.PlayergetWinner()Returns the winner, if one has been determined.booleanisTerminal()Returns true if a winner has been decided or if the game is a tie.java.lang.StringtoString()Statetransition(Move move)Returns the state that would result from taking the given move.
-
Constructor Details
-
State
public State()Constructs the initial state of all Tic Tac Toe games, in which the grid is empty and it is X's turn to move.
-
-
Method Details
-
getCurrentPlayer
Returns the player whose turn it is to move next.- Returns:
- the current player
-
getSquare
Returns the mark at the given row and column of the grid.- Parameters:
row- the row number (0 to 2)column- the column number (0 to 2)- Returns:
- the player who has placed a mark at that location, or null if no player has placed a mark in that location
-
getAvailableMoves
Returns a set of all the next moves that can be made in the game.- Returns:
- all possible next moves
-
transition
Returns the state that would result from taking the given move. Note that this object remains unchanged.- Parameters:
move- the move to take- Returns:
- the resulting state
-
isTerminal
public boolean isTerminal()Returns true if a winner has been decided or if the game is a tie.- Returns:
- true if the game is over, false otherwise
-
getWinner
Returns the winner, if one has been determined.- Returns:
- the winning player, or null if no player has won or the game ended in a tie
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-